﻿; (function (window, undefined, $) {

    $(document).ready(function () {

        var gridopt = {
            url: options.listUrl,
            colModel: [
                    { display: '编号', name: 'ID', width: "5%", sortable: true, hide: false, align: 'left', iskey: true },
                    { display: '审核状态', name: 'Status',hide:true },
                    { display: '企业名称', name: 'EnterpriseName', width: "25%", sortable: true, hide: false, align: 'left', iskey: true },
                    { display: '借款金额', name: 'BorrowAmount', width: "15%", sortable: false, align: 'left' },
                    { display: '借款期限(月)', name: 'LoanPeriod', width: "15%", sortable: false, align: 'left' },
                    { display: '联系方式', name: 'Tel', width: "12%", sortable: false, align: 'left' },
                    //{ display: '注册资金', name: 'RegistedCapital', width: "8%", sortable: false, align: 'left' },
                    { display: '企业概况', name: 'Remarks', width: "15%", sortable: false, align: 'left' },
                    { display: '操作', name: 'ID', width: "25%", sortable: false, align: 'center', process: processOp }
            ],
            sortname: "ID",
            sortorder: "ASC",
            title: false,
            rp: 10,
            usepager: true,
            showcheckbox: false
        };
        var xjgrid = new xjGrid("gridlist", gridopt);
        //function processOp(value, cell) {
        //    var ops = [];
        //    if (cell[1] == 1) {
        //        ops.push("&nbsp;<a title='审核' href='javascript:;'  onclick=\"util.verifytUrl('", value, "')\"><i class='fa fa-edit' ></i>审核</a>");
        //    //} else if (cell[1] == 1) {
        //    //    ops.push("&nbsp;已退回");
        //    } else if (cell[1] == 0) {
        //        ops.push("&nbsp;已通过");
        //    }
        //    return ops.join("");
        //    //ops.push("&nbsp;<a title='编辑' href='javascript:;'  onclick=\"util.Edit('", value, "')\"><i class='fa fa-edit' ></i>编辑</a>");
        //    //ops.push("&nbsp;&nbsp;<a title='删除' class='abtn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' ></i>删除</a>");
        //}
        function processOp(value, cell) {
            var ops = [];
            ops.push("&nbsp;<a title='查看' href='javascript:;'  onclick=\"util.Details('", value, "')\"><i class='fa fa-edit' ></i>查看</a>");
            if (cell[1] == 1) {
                ops.push("&nbsp;<a title='审核' href='javascript:;'  onclick=\"util.verify('", value, "')\"><i class='fa fa-edit' ></i>审核</a>");
                
            } else if (cell[1] == 2) {
                ops.push("&nbsp;已退回");
            } else if (cell[1] == 0) {
                ops.push("&nbsp;已通过");
            }
         ops.push("&nbsp;<a title='删除' href='javascript:;'  onclick=\"util.Delete('", value, "')\"><i class='fa fa-trash-o' ></i>删除</a>");
            //ops.push("&nbsp;&nbsp;<a title='删除' class='abtn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' ></i>删除</a>");
            return ops.join("");
        }
        $("#formQuery").submit(function () {
            xjgrid.Query(this);
            return false;
        });
        $("#btnSearch").click(function () {
            $("#formQuery").submit();
        });
        $("#btnAdd").click(function (e) {
            var url = options.editUrl;
            parent.location.href = url;
        });
        util.verify = function (id,status) {
            $.post(options.verifytUrl + "/" + id, { ID: id ,status:0},
            function (res) {
               if (res.Status > 0) {
                   alert(res.Message);
                   xjgrid.Reload();
               }
               else {
                   alert(res.Message);
               }
            },
        "json"
 );
        };
        util.Edit = function (id) {
            var url = options.editUrl + "/" + id;
            location.href = url;
        };
        util.verify = function (id) {
            var url = options.verifytUrl + "?id=" + id;
            location.href = url;
        };
        util.Details = function (id) {
            var url = options.DetailsUrl + "?id=" + id;
            location.href = url;
        };
        util.Delete = function (id, name) {
            if (!confirm("您确定要执行删除操作吗？")) {
                return false;
            }
            $.post(options.deleteUrl + "/" + id, { id: id },
                  function (res) {
                      if (res.Status > 0) {
                          alert(res.Message);
                          xjgrid.Reload();
                      }
                      else {
                          alert(res.Message);
                      }
                  },
                  "json"
            );
        };
    });

})(window, undefined, jQuery);